﻿package com.ce.pms.occupation.dao.impl;

import java.util.List;

import com.ce.pms.base.dao.impl.PmsBaseDaoImpl;
import com.ce.pms.occupation.dao.IInspecteRequisiteDao;
import com.ce.pms.occupation.model.InspecteRequisiteDO;

/**
 * 验房登记DAO实现
 * @author 王浩羽
 *
 */
public class InspecteRequisiteDaoImpl extends PmsBaseDaoImpl<InspecteRequisiteDO> implements IInspecteRequisiteDao
{

	public List<InspecteRequisiteDO> queryInspecteRequisiteByHouseId(Long houseId)
	{
		StringBuilder hqlBuilder = new StringBuilder();
		hqlBuilder.append("SELECT ").append(" OBJ FROM ").append(InspecteRequisiteDO.class.getSimpleName())
		.append(" AS OBJ WHERE ").append("OBJ.identityValidate.house.keyword = ?");
		return this.createQuery(hqlBuilder.toString(), houseId).list();
	}

	public List<InspecteRequisiteDO> queryInspecteRequisiteByIdentityValidateId(Long identityValidateId)
	{
		StringBuilder hqlBuilder = new StringBuilder();
		hqlBuilder.append("SELECT ").append(" OBJ FROM ").append(InspecteRequisiteDO.class.getSimpleName())
		.append(" AS OBJ WHERE ").append("OBJ.identityValidate.keyword = ?");
		List<InspecteRequisiteDO> list =  this.createQuery(hqlBuilder.toString(), identityValidateId).list();
		return list;
	}

	public Long getTheLastestInspecteRequisiteId( Long identityValidateId)
	{
		StringBuilder hqlBuilder = new StringBuilder();
		hqlBuilder.append("SELECT ").append(" max(OBJ.id) FROM ").append(InspecteRequisiteDO.class.getSimpleName())
		.append(" AS OBJ WHERE ").append("OBJ.identityValidate.keyword = ?");
		List<Long> list =  this.createQuery(hqlBuilder.toString(),identityValidateId).list();
		if(list==null || list.isEmpty())
		{
			return null;
		}
		return list.get(0);
	}

}
